package com.hh.core.listener;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;

import cn.hutool.core.util.ObjectUtil;

import com.hh.core.log.LogManager;
import com.hh.core.log.LogTaskFactory;

public class LoginSessionListener implements SessionListener {

	@Override
	public void onStart(Session session) {

	}

	@Override
	public void onStop(Session session) {// 退出会话
		if (ObjectUtil.isNull(session.getAttribute("id"))) {
			return;
		}
		LogManager.me()
				.executeLog(
						LogTaskFactory.loginLog(2, Long.parseLong(session
								.getAttribute("id").toString()), session
								.getAttribute("ip").toString(), session
								.getAttribute("account").toString()));
		return;
	}

	@Override
	public void onExpiration(Session session) {// 会话过期
		if (ObjectUtil.isNull(session.getAttribute("id"))) {
			return;
		}
		LogManager.me()
				.executeLog(
						LogTaskFactory.loginLog(2, Long.parseLong(session
								.getAttribute("id").toString()), session
								.getAttribute("ip").toString(), session
								.getAttribute("account").toString()));
		return;
	}

}
